package com.feihao.zhou.demo1;


import java.util.HashSet;
import java.util.Iterator;

public class HashSetSavingString {
    public static void main(String[] args) {
        HashSet<String> set = new HashSet<>();
        String s1 = "rrr";
        String s2 = "feihao";
        String s3 = "lidee";
        String s4 = "展会";
        String s5 = "相同";

        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        set.add(s5);

        //存取无序、元素唯一。底层是哈希表。
        System.out.println(set);

        //迭代器遍历：
        /*Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()){
            String s = iterator.next();
            System.out.println(s);
        }*/
        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()) {
            String s = iterator.next();
            System.out.println(s);
        }
        System.out.println("==========");

        //增强for
        for (String s : set) {
            System.out.println(s);
        }
    }
}
